package cn.xo68.boot.auth.server.service;

import java.util.List;

import cn.xo68.boot.auth.core.common.AuthConstants;
import cn.xo68.boot.auth.server.domain.OauthAuthorizationCode;
import cn.xo68.boot.auth.server.mapper.OauthAuthorizationCodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;




/** 
 * OauthAuthorizationCode Service
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月26日 21:54:29
 *
 */
@CacheConfig(cacheNames = {AuthConstants.CACHE_NAME_OAUTH2_AUTHORIZATION_CODE})
 @Service
public class OauthAuthorizationCodeService{
    @Autowired
    private OauthAuthorizationCodeMapper oauthAuthorizationCodeMapper;

    @Cacheable(key = "#authorizationCode")
    public OauthAuthorizationCode get(String authorizationCode) {
        return  oauthAuthorizationCodeMapper.get(authorizationCode);
    }

    @CachePut(key = "#oauthAuthorizationCode.authorizationCode")
    public OauthAuthorizationCode insert(OauthAuthorizationCode oauthAuthorizationCode) {
        oauthAuthorizationCodeMapper.insert(oauthAuthorizationCode);
        return oauthAuthorizationCode;
    }
    @CachePut(key = "#oauthAuthorizationCode.authorizationCode")
    public OauthAuthorizationCode update(OauthAuthorizationCode oauthAuthorizationCode) {
        oauthAuthorizationCodeMapper.update(oauthAuthorizationCode);
        return oauthAuthorizationCode;
    }
    @CacheEvict(key = "#authorizationCode")
    public void delete(String authorizationCode) {
        oauthAuthorizationCodeMapper.delete(authorizationCode);
    }
    
    public List<OauthAuthorizationCode> list() {
        return oauthAuthorizationCodeMapper.list();
    }
	
	public PageInfo<OauthAuthorizationCode> list(int pageNumber,int pageSize) {
        PageHelper.startPage(pageNumber, pageSize,true);
        List<OauthAuthorizationCode> docs = oauthAuthorizationCodeMapper.list();
        PageInfo<OauthAuthorizationCode> pageInfo = new PageInfo<>(docs);
        return pageInfo;
    }
}